export const useSorter = (l: string, r: string) => {
  const l_is_number = isNumber(l);
  const r_is_number = isNumber(r);
  if (l_is_number && r_is_number) {
    return parseFloat(l) - parseFloat(r);
  }
  if (l_is_number) {
    return -1;
  }
  if (r_is_number) {
    return 1;
  }
  const first_l = l[0];
  const first_r = r[0];
  if (!first_l) {
    return -1;
  } else if (!first_r) {
    return 1;
  } else if (first_l != first_r) {
    return first_l.charCodeAt(0) - first_r.charCodeAt(0);
  } else {
    return useSorter(l.slice(1), r.slice(1));
  }
};

const isNumber = (x): x is number => {
  return /^[0-9]/.test(x);
};

// const arr = ['12,测试', '2b', '3c', '中国', '中文', '0bfe'];
// // const arr = [1, 2, 10, 20, 15, 5];

// arr.sort((a, b) => useSorter(a, b));
// console.log('%c Line:32 🥔 list', 'color:#7f2b82', arr);
